package com.live.dengdengtv.bean;

import android.content.Context;
import android.content.SharedPreferences;
import android.view.View;
import android.widget.TextView;

import com.live.dengdengtv.bean.gson.GUserInfo;
import com.tencent.TIMElem;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by wyf on 2016/8/2.
 *
 * 登录信息 + 个人信息 数据存储类
 */
public class LoginInfo {

    private static LoginInfo instance = new LoginInfo();

    private LoginInfo() {
    }

    public static LoginInfo getInstance() {
        return instance;
    }


    private String userId = "";
    private String userSig = "";
    private int roomId;
    private String chatRoomId = "";
    private String userPhone = "";
    private String userPassword = "";

//    private String userNickname = "";
    private String avatarURL;
    private String avatarAdress;
//    private String userSex;
//    private String userSign;
    private String userAdrress;
    private String userAge;
    private String userMarital;

    private GUserInfo gUserInfo;

    private List<String> bannerList;
    private List<ChatMessage> curChat = new ArrayList<>();//聊天界面
    private List<ChatMessage> chatFriendList = new ArrayList<>();//TODO: 持久化到本地
    private List<ChatMessage> chatStrangerList = new ArrayList<>();;

    public List<ChatMessage> getChatFriendList() {
        return chatFriendList;
    }

    public List<ChatMessage> getChatStrangerList() {
        return chatStrangerList;
    }

    public List<ChatMessage> getCurChat() {
        return curChat;
    }
    /**当前聊天对象的 id*/
    private String curChatId ="";

    public String getCurChatId() {
        return curChatId;
    }

    public void setCurChatId(String curChatId) {
        this.curChatId = curChatId;
    }
    //    public static void setInstance(LoginInfo instance) {
//        LoginInfo.instance = instance;
//    }

    public String getUserId() {
        return userId;
    }

    public void setUserId(String userId) {
        this.userId = userId;
    }

    public String getUserSig() {
        return userSig;
    }

    public void setUserSig(String userSig) {
        this.userSig = userSig;
    }

    public void setRoomId(int roomId) {
        this.roomId = roomId;
    }

    public int getRoomId() {
        return roomId;
    }

    public String getChatRoomId() {
        return chatRoomId;
    }

    public void setChatRoomId(String chatRoomId) {
        this.chatRoomId = chatRoomId;
    }

    public String getUserPhone() {
        return userPhone;
    }

    public void setUserPhone(String userPhone) {
        this.userPhone = userPhone;
    }

    public String getUserPassword() {
        return userPassword;
    }

    public void setUserPassword(String userPassword) {
        this.userPassword = userPassword;
    }

    public String getUserNickname() {
        return gUserInfo.nickname;
    }

    public void setUserNickname(String userNickname) {
        this.gUserInfo.nickname = userNickname;
    }

    public String getAvatarURL() {
        return avatarURL;
    }

    public void setAvatarURL(String avatarURL) {
        this.avatarURL = avatarURL;
    }

    public String getAvatarAddress() {
        return gUserInfo.image_url;
    }

    public void setAvatarAddress(String avatarAddress) {
        this.gUserInfo.image_url = avatarAddress;
    }

    public String getUserSex() {
        return gUserInfo.sex;
    }

    public void setUserSex(String userSex) {
        this.gUserInfo.sex = userSex;
    }

    public String getUserSign() {
        return gUserInfo.self_description;
    }

    public void setUserSign(String userSign) {
        this.gUserInfo.self_description = userSign;
    }

    public String getUserAdrress() {
        return userAdrress;
    }
    public void setUserAdrress(String userAdrress) {
        this.userAdrress = userAdrress;
    }

    public String getUserProvinceId() {
        return gUserInfo.home_province_id;
    }
    public void setUserProvinceId(String provinceId) {
        this.gUserInfo.home_province_id = provinceId;
    }
    public String getUserCityId() {
        return gUserInfo.home_city_id;
    }
    public void setUserCityId(String cityId) {
        this.gUserInfo.home_city_id = cityId;
    }

    public String getUserBirthday() {
        return gUserInfo.birthday;
    }

    public void setUserBirthday(String birthday) {
        this.gUserInfo.birthday = birthday;
    }
    public String getUserAge() {
        return userAge;
    }

    public void setUserAge(String userAge) {
        this.userAge = userAge;
    }

    public String getUserMarital() {
        return gUserInfo.emotion_type;
    }

    public void setUserMarital(String userMarital) {
        this.gUserInfo.emotion_type = userMarital;
    }

    public int getUserLevel() {
        return gUserInfo.level;
    }

    public void setUserLevel(int level) {
        this.gUserInfo.level = level;
    }

    public int getVirCoin(){
        int virCoin = 0;
        try {
            virCoin = Integer.parseInt(gUserInfo.virtual_coin);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return virCoin;
    }
    public void setVirCoin(String virCoin){
        gUserInfo.virtual_coin = virCoin;
    }
    public void addVirCoin(String value){
        try {
            int currVirCoin = Integer.parseInt(gUserInfo.virtual_coin);
            int addValue = Integer.parseInt(value);
            gUserInfo.virtual_coin = (currVirCoin+addValue)+"";
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    public void subtractVirCoin(String value){
        try {
            int currVirCoin = Integer.parseInt(gUserInfo.virtual_coin);
            int subValue = Integer.parseInt(value);
            gUserInfo.virtual_coin = (currVirCoin - subValue)+"";
        } catch (Exception e) {
            e.printStackTrace();
        }
    }


    public int getVirTicket(){
        int virTicket = 0;
        try {
            virTicket = Integer.parseInt(gUserInfo.virtual_ticket);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return virTicket;
    }
    public void addVirTicket(String value){
        try {
            int currVirTicket = Integer.parseInt(gUserInfo.virtual_coin);
            int addValue = Integer.parseInt(value);
            gUserInfo.virtual_ticket = (currVirTicket+addValue)+"";
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public GUserInfo getgUserInfo() {
        return gUserInfo;
    }

    public void setgUserInfo(GUserInfo gUserInfo) {
        this.gUserInfo = gUserInfo;
    }

    public List<String> getBannerList() {
        return bannerList;
    }

    public void setBannerList(List<String> bannerList) {
        this.bannerList = bannerList;
    }

    public void holdLoginInfo(Context context){
        SharedPreferences sp = context.getSharedPreferences(AppConstants.SP_LOGIN, Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = sp.edit();
        editor.putString("userPhone", userPhone);
        editor.putString("userPassword", userPassword);
        editor.commit();
    }
    public void holdMyEdit(ArrayList<View> editViewList) {
        avatarAdress = (String) editViewList.get(0).getTag();
        setAvatarAddress(avatarAdress);

        String userNickname = ((TextView) editViewList.get(1)).getText().toString();
        setUserNickname(userNickname);

        String userSex = ((TextView) editViewList.get(2)).getText().toString();
        if("男".equals(userSex)){
            userSex = "1";
        }else if("女".equals(userSex)){
            userSex = "2";
        }else {
            userSex = "3";
        }
        setUserSex(userSex);

        String userSign = ((TextView) editViewList.get(3)).getText().toString();
        setUserSign(userSign);

        userAdrress = ((TextView) editViewList.get(4)).getText().toString();
        userAge = ((TextView) editViewList.get(5)).getText().toString();
        userMarital =  ((TextView) editViewList.get(6)).getText().toString();
        setUserMarital(userMarital);
    }
}
